


*-----------Varibale preparation----------------

*create experimental conditions
*name_r=1 is Japanese, name_r=2 is American, and name_r=3 is Chinese names. 
gen name_r=.
replace name_r=1 if name=="誠一郎"
replace name_r=2 if name=="ジェームズ"
replace name_r=3 if name=="超鴻（チョウコウ）"

*origin_r=1 is Japanese, origin_r=2 is American, and origin_r=3 is Chinese names. 
gen origin_r=.
replace origin_r=1 if origin=="近隣の自治体からこの選挙区に移り住んできました"
replace origin_r=2 if origin=="アメリカからこの選挙区に移り住み、日本国籍に帰化しました"
replace origin_r=3 if origin=="中国からこの選挙区に移り住み、日本国籍に帰化しました"
tab origin_r

*policy_restrict=0 indicates more equal policy between migrants and Japanese, and policy_restrict=1 is opposing against migrants. 
gen policy_restrict=.
replace policy_restrict=0 if policy=="永住外国人の地方参政権を始めとする市民の平等な政治参加を促進すること"
replace policy_restrict=1 if policy=="永住外国人の地方参政権に断固反対し日本人第一の社会づくりを行うこと"

*combining two experimental variables
*variables used for Figure 2
gen nameorigin=.
replace nameorigin=0 if name_r==1 & origin_r==1
replace nameorigin=1 if name_r==1 & origin_r==2
replace nameorigin=2 if name_r==2 & origin_r==2
replace nameorigin=3 if name_r==1 & origin_r==3
replace nameorigin=4 if name_r==3 & origin_r==3

*variables used for Figure 3
gen jorigin_policy_3=.
replace jorigin_policy_3=0 if origin_r==1
replace jorigin_policy_3=1 if (origin_r==2 & policy_restrict==0)
replace jorigin_policy_3=2 if (origin_r==3 & policy_restrict==0)
replace jorigin_policy_3=3 if (origin_r==2 & policy_restrict==1)
replace jorigin_policy_3=4 if (origin_r==3 & policy_restrict==1)

*threats
factor q81_1 q81_2 q81_3
rotate, promax blank(.3)
predict threat_f


*dependent variable. q135 is Q13.5 in csv
gen willingness_vote=.
replace willingness_vote= 6-q135

*dependent variable for robustness (FigureA2-F4) 
gen favorability=.
replace favorability= 6-q134

*Manipulation checks
gen attention1=0
replace attention1=1 if origin_r==1 & q141==2
replace attention1=1 if origin_r==2 & q141==3
replace attention1=1 if origin_r==3 & q141==4

gen attention2=0
replace attention2=1 if policy_restrict==0 & q142==1
replace attention2=1 if policy_restrict==1 & q142==2

tab attention2

gen attention3=0
replace attention3=1 if  q143==1

gen attentionall=0
replace attentionall=1 if attention1==1 & attention2==1 & attention3==1


*descriprive statistics (q22 is labled as Q2.2 in csv)
gen gender=3
replace gender=1 if q22==1 
replace gender=2 if q22==2
tab gender

gen edu=.
replace edu=1 if q26==1 | q26==2
replace edu=2 if q26==3 | q26==4 |q26==5
replace edu=3 if q26==6
replace edu=4 if q26>6

gen conservative=q53
gen age=q21


*-------------------Analyses in the main text--------------------------------------------


* Figure 1
reg willingness_vote i.origin_r i.name_r i.policy_restrict  

coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons ) omitted baselevels  xline(0) ///
headings(1.origin_r = "{bf:Origin}" 1.name_r = "{bf:Name}" ///
0.policy_restrict = "{bf:Policy}" , labsize(medium))


*Figure 2
reg willingness_vote i.nameorigin i.policy_restrict

coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons 0.policy_restrict 1.policy_restrict ) omitted baselevels  xline(0) 


*Figure 3
reg willingness_vote i.jorigin_policy_3 i.name_r   

coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons 1.name_r 2.name_r 3.name_r ) omitted baselevels  xline(0) 


*Figure 4
reg willingness_vote (i.origin_r i.name_r i.policy_restrict)##c.threat_f

margins, at( origin_r=( 1 2 3 ) threat_f=(-1 0 1) ) vsquish
marginsplot



*Figure 5
reg willingness_vote (i.nameorigin i.policy_restrict)##c.threat_f

margins, at( nameorigin=(0 1 2 3 4) threat_f=(-1 0 1) ) vsquish
marginsplot


*Figure 6
reg willingness_vote (i.jorigin_policy_3 i.name_r)##c.threat_f   

margins, at( jorigin_policy_3=(0 1 2 3 4) threat_f=(-1 0 1) ) vsquish
marginsplot




*-------------------Analyses in the Appendix--------------------------------------------

* Figure A1
reg willingness_vote i.origin_r i.name_r i.policy_restrict if attentionall==1

coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons ) omitted baselevels  xline(0) ///
headings(1.origin_r = "{bf:Origin}" 1.name_r = "{bf:Name}" ///
0.policy_restrict = "{bf:Policy}" , labsize(medium))


*Figure A2
reg favorability i.origin_r i.name_r i.policy_restrict  


coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons ) omitted baselevels  xline(0) ///
headings(1.origin_r = "{bf:Origin}" 1.name_r = "{bf:Name}" ///
0.policy_restrict = "{bf:Policy}" , labsize(medium))


*Figure A3
reg favorability i.nameorigin i.policy_restrict

coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons ) omitted baselevels  xline(0) ///
headings(1.origin_r = "{bf:Origin}" 1.name_r = "{bf:Name}" ///
0.policy_restrict = "{bf:Policy}" , labsize(medium))


*Figure A4
reg favorability i.jorigin_policy_3 i.name_r   

coefplot ,  ylabel(,labsize(medsmall)) xlabel(,labsize(medsmall)) msize(medsmall) drop(_cons ) omitted baselevels  xline(0) ///
headings(1.origin_r = "{bf:Origin}" 1.name_r = "{bf:Name}" ///
0.policy_restrict = "{bf:Policy}" , labsize(medium))


*Table A1
sum age
tab gender
tab education
sum conservative




